<script>
export default {
  onLaunch: function () {
    // 初始化关卡状态
    const levels = uni.getStorageSync('gameLevels') || [];
    if (levels.length === 0) {
      const initialLevels = Array(9).fill().map((_, i) => ({
        unlocked: i === 0, // 默认解锁第一关
        completed: false
      }));
      uni.setStorageSync('gameLevels', initialLevels);
    }
  }, globalData: {
    checkLevelStatus(level) {
      const levels = uni.getStorageSync('gameLevels');
      // 关卡索引从0开始，level参数从1开始
      return levels[level - 1] || { unlocked: false, completed: false };
    }, updateLevelStatus(level, isCompleted) {
      const levels = uni.getStorageSync('gameLevels');
      const index = level - 1;
      // 更新当前关卡状态
      levels[index] = {
        unlocked: true, completed: isCompleted
      };
      // 解锁下一关（如果存在）
      if (levels[index + 1]) {
        levels[index + 1].unlocked = true;
      }
      uni.setStorageSync('gameLevels', levels);
    }
  }
}
</script>

<style lang="scss">
@import "uview-plus/index.scss";
/*每个页面公共css */

.uni-tabbar {
  box-shadow: #aaa 0 0 10px;
}

.flex {
  display: flex;
}

.flex-wrap {
  flex-wrap: wrap;
}

.column {
  flex-direction: column;
}

.center {
  align-items: center;
  justify-content: center;
}

.a-i-c {
  align-items: center;
}

.j-c-c {
  justify-content: center;
}

.pad-1 {
  padding: 24rpx;
}

.pad-2 {
  padding: 36rpx;
}

.pad-3 {
  padding: 48rpx;
}

.pad-4 {
  padding: 64rpx;
}

.gap-12 {
  gap: 12rpx;
}

.gap-1 {
  gap: 24rpx;
}

.gap-2 {
  gap: 36rpx;
}

.gap-3 {
  gap: 48rpx;
}

.gap-4 {
  gap: 64rpx;
}

.f-s-1 {
  font-size: 26rpx;
}

.f-s-2 {
  font-size: 36rpx;
}

.f-s-3 {
  font-size: 48rpx;
}

.f-w-b {
  font-weight: bold;
}

.full {
  width: 100%;
  height: 100%;
}

.j-c-s-b {
  justify-content: space-between;
}

.j-c-s-a {
  justify-content: space-around;
}

.w-90 {
  width: 90%;
}

.corner-width {
  width: 30rpx;
}

.pad-0 {
  padding: 12rpx;
}
</style>
